package org.xx.armory.config;


/**
 * 基本的配置提供程序的实现。
 * <p>此类型可以通过文件或者流加载配置内容。</p>
 */
abstract class AbstractConfigurationProvider
        implements ConfigurationProvider {
    private final Object configurationLock = new Object();
    private volatile Configuration configuration;

    /**
     * {@inheritDoc}
     */
    @Override
    public Configuration get() {
        Configuration configuration = this.configuration;
        if (configuration == null) {
            synchronized (configurationLock) {
                configuration = this.configuration;
                if (configuration == null) {
                    configuration = load();
                }

                this.configuration = configuration;
            }
        }

        return this.configuration;
    }

    /**
     * 加载配置。
     *
     * @return 已加载的配置。
     */
    protected abstract Configuration load();
}
